home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest1_0.lha / Tests / burner / burner.C next >
C/C++ Source or Header  |  1991-12-11  |  2KB  |  112 lines

  1. //
  2. // An extremely simple Presto thread exerciser.  T threads
  3. // run on N processors with preemption quantum Q milliseconds.
  4. // Each thread spins for S iterations in a tight loop, prints
  5. // an identifying string, and exits.
  6. //
  7. // Jeff Chase 8/15/88
  8. //
  9.  
  10. #include "presto.h"
  11. #include "burner.h"
  12.  
  13. //
  14. // These are runtime parameters set from command-line arguments.
  15. // Also: numprocessors, quantum
  16. //
  17. int burnercount = 5;
  18. int spins = 500000;
  19.  
  20. burner::burner(int ident, int stop)
  21. {
  22.     spincount = 0;
  23.     stopcount = stop;
  24.     id = ident;
  25. }
  26.  
  27. burner::~burner()
  28. {
  29. }
  30.  
  31. void
  32. burner::run()
  33. {
  34.     bthread = new Thread("burner");
  35.     bthread->willjoin();
  36.     bthread->start(this, (PFany)(burner::spin));
  37. }
  38.  
  39. void
  40. burner::spin(burner *b)
  41. {
  42.     int i;
  43.  
  44.     while(b->spincount <= b->stopcount) {
  45.         for (i = 0; i < 1000; i++) b->spincount++;
  46.     } 
  47.     //
  48.     // There should probably be some protection on the couts.
  49.     //
  50.     cout << '(' << b->id << ')' << flush;
  51. }
  52.  
  53. int
  54. burner::join()
  55. {
  56.     return((int)(bthread->join()));
  57. }
  58.  
  59. Main::init()
  60. {
  61.     numprocessors = 1;
  62.     quantum = 0;
  63.  
  64.     for (argc--, argv++; *argv && **argv == '-'; argv++, argc--)
  65.         switch (*(*argv + 1)) {
  66. #ifdef sequent
  67. #ifdef i386
  68.                 case 'a':
  69.                         affinity = 1;
  70.                 break;
  71. #endif /* i386 */
  72. #endif /* sequent */
  73.             case 'q':
  74.                 quantum = atoi(*argv + 2);
  75.                 break;
  76.             case 'n':
  77.                 numprocessors = atoi(*argv + 2);
  78.                 break;
  79.             case 's':
  80.                 spins = atoi(*argv + 2);
  81.                 break;
  82.             case 't':
  83.                 burnercount = atoi(*argv + 2);
  84.                 break;
  85.             default:
  86.                 cerr << chr(*(*argv + 1)) << " unknown flag.\n";
  87.                     return -1;
  88.         }
  89.     return 0;
  90. }
  91.  
  92. Main::main()
  93. {
  94.  
  95.     Oqueue burnerq;
  96.     burner *b;
  97.     int i;
  98.  
  99.     for(i = 0; i < burnercount; i++) {
  100.         b = new burner(i, spins);
  101.         burnerq.append(b);
  102.         b->run();
  103.     }
  104.  
  105.     while((b = (burner *)burnerq.get()) != NULL)
  106.         b->join();
  107.  
  108.     cout << "...done.\n";
  109. }
  110.  
  111.  
  112.